package com.springboot.seckill.validator;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @Author: HuangDekai
 * @Date: 2022/3/16 12:56
 * @Version: 1.0
 * @since: jdk11
 */
public class ValidationResult {
    /**
     * 校验结果是否有错
     */
    private boolean hasErrors = false;

    /**
     * 存放错误信息
     */
    private Map<String, String> errorMsgMap;

    public boolean isHasErrors() {
        return hasErrors;
    }

    public void setHasErrors(boolean hasErrors) {
        this.hasErrors = hasErrors;
    }

    public Map<String, String> getErrorMsgMap() {
        return errorMsgMap;
    }

    public void setErrorMsgMap(Map<String, String> errorMsgMap) {
        this.errorMsgMap = errorMsgMap;
    }

    /**
     * 实现通用的通过格式化字符串信息获取错误结果的方法
     * @return 错误结果
     */
    public String getErrMsg() {
        return StringUtils.join(errorMsgMap.values().toArray(), ",");
    }
}
